package com.qimei.onerice.service.impl;

import com.qimei.onerice.dao.CommentDao;
import com.qimei.onerice.dao.DishCategoryDao;
import com.qimei.onerice.dao.impl.CommentDaoImpl;
import com.qimei.onerice.dao.impl.DishCategoryDaoImpl;
import com.qimei.onerice.entity.Comment;
import com.qimei.onerice.entity.Customer;
import com.qimei.onerice.entity.DishCategory;
import com.qimei.onerice.service.CommentService;
import com.qimei.onerice.service.CustomerService;
import jdk.nashorn.internal.ir.CallNode;

import java.util.List;

public class CommentServiceImpl implements CommentService {
	CommentDao commentDao = new CommentDaoImpl();
	CustomerService customerService = new CustomerServiceImpl();

	@Override
	public List<Comment> getCommentListByDishId(int dishId) {
		List<Comment> commentListByDishId = commentDao.getCommentListByDishId(dishId);
		for (Comment comment : commentListByDishId) {
			Customer customer = customerService.getCustomerById(comment.getCustomerId());
			if (customer != null) {
				comment.setCustomerName(customer.getCustomerName());
				comment.setCustomerImage(customer.getCustomerImage());
			}
		}
		return commentListByDishId;
	}

	@Override
	public boolean deleteComment(int commentId) {
		int result = commentDao.deleteComment(commentId);
		return result > 0;
	}

	@Override
	public boolean updateComment(Comment comment) {
		int result = commentDao.updateComment(comment);
		return result > 0;
	}

	@Override
	public boolean addComment(Comment comment) {
		int result = commentDao.addComment(comment);
		return result > 0;
	}

	@Override
	public Comment getCommentById(int commentId) {
		return commentDao.getCommentById(commentId);
	}
}
